<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLuckyBagsTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::create('lucky_bags', function (Blueprint $table) {
            $table->timestamp('updated_at')->useCurrent();
            $table->timestamp('created_at');

            $table->increments('id');
            $table->integer('student_id')->comment('分享用户ID');
            $table->integer('appointment_id')->coment('预约ID');
            $table->string('share_code')->comment('分享code');
            $table->integer('grab_num')->default(0)->comment('被领取次数');
            $table->tinyInteger('status')->default(1)->comment('状态[1正常,2抢完]');

            $table->softDeletes();

            $table->index('appointment_id');
            $table->index('student_id');
            $table->index('share_code');
        });
        Schema::create('lucky_bag_logs', function (Blueprint $table) {
            $table->timestamp('updated_at')->useCurrent();
            $table->timestamp('created_at');

            $table->increments('id');
            $table->integer('bag_id')->comment('福袋ID');
            $table->integer('student_id')->comment('领取用户ID');
            $table->integer('type')->comment('福袋奖品类型');
            $table->decimal('amount')->default(0)->comment('奖学金金额');

            $table->softDeletes();

            $table->index('student_id', 'type');
            $table->index('bag_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::drop('lucky_bags');
        Schema::drop('lucky_bag_logs');
    }
}
